package aaa;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class fz {
    /**
     * MyBatis工具类
     * @version 1.0
     * @since 1.0
     */
        private static SqlSessionFactory sqlSessionFactory;

        /**
         * 类加载时初始化sqlSessionFactory对象
         */
        static {
            try {
                SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
                sqlSessionFactory = sqlSessionFactoryBuilder.build(Resources.getResourceAsStream("mybatis-config.xml"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        /**
         * 每调用一次openSession()可获取一个新的会话，该会话支持自动提交。
         *
         * @return 新的会话对象
         */
        public static SqlSession openSession() {
            return sqlSessionFactory.openSession(true);
        }
    }

